import store from '../store'

const router = new VueRouter({
  routes: [
    {
      path: '/',
      name: 'main',
      redirect: '/me',
      component: () => import('@/components/main'),
      children: [
        {
          path: '/me',
          name: 'me',
          redirect: '/me/index',
          component: () => import('@/components/me'),
          children: [
            {
              path: 'index',
              name: 'meIndex',
              component: () => import('@/components/me/index')
            },
            // ------start-----   个人中心相关路由
            // 个人设置
            {
              path: 'settings',
              name: 'settings',
              component: () => import('@/components/me/settings')
            },
            // 换绑手机
            {
              path: 'changePhone',
              name: 'changePhone',
              component: () => import('@/components/me/changePhone')
            },
            // 绑定手机
            {
              path: 'bindingPhone',
              name: 'bindingPhone',
              component: () => import('@/components/me/bindingPhone')
            },
            // 防沉迷认证
            {
              path: 'certification',
              name: 'certification',
              component: () => import('@/components/me/certification')
            },
            // 修改密码
            {
              path: 'changePass',
              name: 'changePass',
              component: () => import('@/components/me/changePass')
            },
            // 我的消息
            {
              path: 'myMessage',
              name: 'myMessage',
              component: () => import('@/components/me/myMessage')
            },
            // 优惠券
            {
              path: 'coupon',
              name: 'coupon',
              component: () => import('@/components/me/coupon')
            },
            //我的优惠券
            {
              path: 'myCoupon',
              name: 'myCoupon',
              component: () => import('@/components/me/myCoupon')
            },
            // 游戏礼包
            {
              path: 'gamePackage',
              name: 'gamePackage',
              component: () => import('@/components/me/gamePackage')
            },
            // 游戏活动
            {
              path: 'playActivity',
              name: 'playActivity',
              component: () => import('@/components/me/playActivity')
            },
            // 联系客服
            {
              path: 'customService',
              name: 'customService',
              component: () => import('@/components/me/customService')
            },
            // 我的小号
            {
              path: 'myTrumpet',
              name: 'myTrumpet',
              component: () => import('@/components/me/myTrumpet')
            },
            // 订单记录
            {
              path: 'orderRecord',
              name: 'orderRecord',
              component: () => import('@/components/me/orderRecord')
            },
            // 游戏礼包详情
            {
              path: 'packageDetails/:id',
              name: 'packageDetails',
              component: () => import('@/components/me/packageDetails')
            },
            // 活动详情
            {
              path: 'activityDetails/:id',
              name: 'activityDetails',
              component: () => import('@/components/me/activityDetails')
            },
            {
              path: 'gmpay',
              name: 'gmpay',
              component: () => import('@/components/me/gmpay')
            },
          ]
        },
        {
          path: '/web',
          name: 'web',
          redirect: '/web/index',
          component: () => import('@/components/web'),
          children: [
            {
              path: 'index',
              name: 'index',
              component: () => import('@/components/web/index')
            }
          ]
        },
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  store.commit('UPDATE_LOADING_STATUS', {isLoading: true})
  store.commit('RESET_STATUS')
  next()
})

router.afterEach((to, from) => {
  store.commit('UPDATE_LOADING_STATUS', {isLoading: false})
})

export default router
